﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.membercenter.accountrun
{
    public partial class collection_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["MemberID"] == null)
                {
                    ChangeHope.WebPage.Script.AlertAndGoBack("温馨提示：登录超时，请重新登录！");
                }
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != string.Empty)
                {
                    string types = Request.Form["Option"].Trim();
                    string StrID = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        Del(StrID);
                    }
                    Response.End();
                    return;
                }
                this.lblList.Text = GetList();

            }
        }

        /// <summary>
        /// 积分来源(1商品订单,2评论,3登陆)
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected string GetList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.BLL.Accessories.Collection bll = new YXShop.BLL.Accessories.Collection();
            YXShop.BLL.Product.ProductInfo ProBll = new YXShop.BLL.Product.ProductInfo();
            ChangeHope.DataBase.DataByPage dataPage = bll.GetList(" 1=1 and collectionuid=" + Session["MemberID"].ToString());
            //第一步先添加表头
            table.AddHeadCol("", "图片");
            table.AddHeadCol("", "商品名称");
            table.AddHeadCol("", "价格");
            table.AddHeadCol("", "收藏时间");
            table.AddHeadCol("", "操作");
            table.AddRow();
            //添加表的内容
            if (dataPage.DataReader != null)
            {
                while (dataPage.DataReader.Read())
                {
                    int proId= Convert.ToInt32(dataPage.DataReader["collectionid"].ToString());
                    YXShop.Model.Product.ProductInfo ProModel = ProBll.GetModel(proId);
                    if (ProModel != null)
                    {
                        YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
                        table.AddCol(string.Format("<img src=\"{0}\" style=\"height:48px; width:68px;\" alt=\"{1}\"/>", sp.DummyPaht + ProModel.pro_Thumbnail, ProModel.pro_Name));
                        string url = YXShop.TemplateAction.Common.UrlStr("productcontent", "q_productid=" + dataPage.DataReader["collectionid"].ToString(), "product/");
                        table.AddCol(string.Format("<a href='{0}' target='_blank'>{1}</a>", url, ProModel.pro_Name));
                        table.AddCol(ProModel.pro_ShopPrice.ToString());
                        table.AddCol(dataPage.DataReader["collectiondate"].ToString());
                        table.AddCol(string.Format("<a href='javascript:void(0)' onclick='Del({0})'>删除</a>", dataPage.DataReader["id"].ToString()));
                        table.AddRow();
                    }
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }

        private void Del(string id)
        {
            YXShop.BLL.Accessories.Collection bll = new YXShop.BLL.Accessories.Collection();
            bll.Delete(id);
            Response.Write("ok");
        }
    }
}
